using System;
using BSGen;

namespace BSGen32
{
    class Program
    {
        static string inputAssembly = "";
        static string outputFolder = "";

        static void Main(string[] args)
        {
            ParameterErrors errors = parseParameters(args);
            if (errors == ParameterErrors.None)
            {
                CodeGenerator cg = new CodeGenerator();
                cg.GenerateCode(inputAssembly, outputFolder);
            }
            else
            {
                displayErrors(errors);
            }
        }

        public enum ParameterErrors
        {
            None,
            InvalidParametersCount,
            InputAssemblyFileNotFound,
            OutputFolderNotFound,
        }

        private static ParameterErrors parseParameters(string[] args)
        {
            //check parameter numbers
            if (args.Length < 2) return ParameterErrors.InvalidParametersCount;

            //check input assembly
            inputAssembly = args[0];
            if (!System.IO.File.Exists(inputAssembly))
            {
                return ParameterErrors.InputAssemblyFileNotFound;
            }

            //check output folder
            outputFolder = args[1];
            if (!System.IO.Directory.Exists(outputFolder))
            {
                return ParameterErrors.OutputFolderNotFound;
            }

            return ParameterErrors.None;
        }

        private static void displayErrors(ParameterErrors errors)
        {
            switch (errors)
            {
                case ParameterErrors.InputAssemblyFileNotFound:
                    Console.WriteLine(String.Format("Input file not found: {0}", inputAssembly));
                    break;
                case ParameterErrors.OutputFolderNotFound:
                    Console.WriteLine(String.Format("Invaild output folder specified: {0}", outputFolder));
                    break;
                case ParameterErrors.InvalidParametersCount:
                    Console.WriteLine("Invalid parameters. USAGE: BSGen [AssemblyFile] [OutputFolder]");
                    break;
            }
        }

    }
}

